﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace ReactiveCode
{

    [ContractClass(typeof(IEnumerableObserverContract<>))]
    public interface IEnumerableObserver<T>
    {
        void OnReset(IEnumerable<IObservable<T>> items);
        void OnAdded(IObservable<T> item, int index);
        void OnRemoved(IObservable<T> item, int index);

        void OnError(Exception error);
        void OnCompleted();
    }

    #region Contract for IEnumerableObserver<T>

    [ContractClassFor(typeof(IEnumerableObserver<>))]
    abstract class IEnumerableObserverContract<T> : IEnumerableObserver<T>
    {
        public void OnReset(IEnumerable<IObservable<T>> items)
        {
            Contract.Requires<ArgumentNullException>(items != null, "items");
        }

        public void OnAdded(IObservable<T> item, int index)
        {
            Contract.Requires<ArgumentNullException>(item != null, "item");
        }

        public void OnRemoved(IObservable<T> item, int index)
        {
            Contract.Requires<ArgumentNullException>(item != null, "item");
        }

        public void OnError(Exception error)
        {
            Contract.Requires<ArgumentNullException>(error != null, "error");
        }

        public void OnCompleted()
        {
        }
    }

    #endregion
}
